<?php

class Feedback_Form_Feedback extends Zend_Form
{
    protected $_user;
    
    public function __construct()
    {
        $this->_user=Zend_Registry::get('user');
        
        parent::__construct();
    }
    
    public function init()
    {
        $this->setMethod('POST');
        $this->setAction(Zend_Registry::get('view')->fixUrl('feedback'));
        
        $name=new Zend_Form_Element_Text('name');
        $name->setLabel('Name')
              ->addFilter('StringTrim')
              ->addFilter('StripTags')
              ->addValidator(
                    'StringLength',
                    true,
                    array(
                        'min' => 2,
                        'max' => 255
                    )
              )
              ->addDecorator(new Feedback_Form_FeedbackDecorator())
              ->setValue($this->_user)
              ->setRequired(true);
        
        $email=new Zend_Form_Element_Text('email');
        $email->setLabel('E-Mail')
              ->addFilter('StringTrim')
              ->addValidator(
                    'EmailAddress',
                    true
              )
              ->addDecorator(new Feedback_Form_FeedbackDecorator())
              ->setValue($this->_user->email)
              ->setRequired(true);
        
        $message=new Zend_Form_Element_Textarea('message');
        $message->setLabel('Message')
              ->addFilter('StringTrim')
              ->addFilter('StripTags')
              ->addValidator(
                    'StringLength',
                    true,
                    array(
                        'min' => 10,
                        'max' => 5000
                    )
              )
              ->addDecorator(new Feedback_Form_FeedbackDecorator())
              ->setRequired(true);
         
        $this->addElements(
            array(
                $name,
                $email,
                $message
                )
        );
        
        $this->addElement('captcha', 'captcha', array(
            'label'      => 'CAPTCHA',
            'captcha'    => array(
                'captcha' => 'Image',
                'font' => ROOT_DIR.'/data/misc/FreeSerifBold.ttf',
                'fontSize' => 24,
                'imgDir' => ROOT_DIR.'/data/tmp/captcha',
                'imgUrl' => Zend_Registry::get('view')->baseUrl('data/tmp/captcha'),
                'wordLen' => 6,
                'timeout' => 300,
                'width' => 200,
                'height' => 50
            ),
            'decorators' => array(
                                new Feedback_Form_FeedbackDecorator()
                              ),
            'required'   => true
        ));
              
         $submit=new Zend_Form_Element_Submit('submit');
         $submit->setValue('Send')
                ->setLabel('')
                ->addDecorator(new Feedback_Form_FeedbackDecorator());
               
         $csrf=new Zend_Form_Element_Hash('csrf',array('salt' => 'feedback'));
         $csrf->setOptions(array(
                            'ignore' => true,
                        ))
              ->addDecorator(new Feedback_Form_FeedbackDecorator());
              
        $this->addElements(
            array(
                $submit,
                $csrf
                )
        );
    }
}

